﻿<%@ WebHandler Language="C#" Class="SIPO.Web.AjaxHandler.Transaction.recDendahandler" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.DataAccess.Administration;
using SIPO.Library.DomainObject.Administration;

using SIPO.Library.Enum;
using SIPO.Web.Support;

using Newtonsoft.Json.Linq;
namespace SIPO.Web.AjaxHandler.Transaction
{

    public class recDendahandler : SIPO.Web.BaseHandler
    {
        private recDendaRepo recDenda = new recDendaRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
       private recLogRepo logDal = new recLogRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        private string MethodName = string.Empty;
        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            MethodName = context.Request.Params["method"];

            context.Response.Clear();
            context.Response.Buffer = true;

            switch (MethodName.ToLower())
            {
                case ("insert"):
                    context.Response.Write(Insert(context));
                    break;
          //      case ("getdata"):
            //        context.Response.Write(GetData(context));
              //      break;
                default:
                    // do nothing
                    break;
            }

        }

        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private string Insert(HttpContext context)
        {
            JSONHelper helper = new JSONHelper();
            try
            {
                recDenda.Save(base.UserLoggedIn);//run [dbo].[SP_GenDenda]

                helper.Message = "Perhitungan selesai !";
                helper.IsSuccess = true;
            }
            catch
            {
                helper.IsSuccess = false;
                helper.Message = "Perhitungan gagal !";
            }
            finally
            {
                recLog log = new recLog();
                log.LogEvent = "Insert";
                log.LogMessage = helper.Message;
                log.LogSource = "recDendahandler.ashx";
                log.CreatedBy = base.UserLoggedIn;
                log.CreatedDate = DateTime.Now;
                logDal.Save(log);
            }
            return Newtonsoft.Json.JsonConvert.SerializeObject(helper);
        }

      }

    }

